package com.tz.controller;

import com.tz.entity.Research;
import com.tz.entity.ResearchDetail;
import com.tz.entity.json.PollDetails;
import com.tz.service.ResearchDetailService;
import com.tz.service.ResearchService;
import com.tz.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 侯畅畅 on 2018/1/4.
 */
@Controller
@RequestMapping("/check")
public class CheckController {
    @Autowired
    ResearchService researchService;
    @Autowired
    ResearchDetailService researchDetailService;
    @ResponseBody
    @RequestMapping(value = "/showResearch", produces = "application/json")
    public PageBean<Research> showResearch(){
        return researchService.findResearchsByPage(1,7,2,null);
    }
    @ResponseBody
    @RequestMapping(value = "/showDetail", produces = "application/json")
    public Research showDetail(@RequestBody Long researchid){
        Research research = researchService.findById(researchid);
        List<ResearchDetail> researchDetails = researchDetailService.gainAllDetails(researchid);
        research.setResearchDetails(researchDetails);
        System.out.println(research);
        return  research;
    }
    @ResponseBody
    @RequestMapping(value = "/showOneResearchDetail", produces = "application/json")
    public List<PollDetails> showOneResearchDetail(@RequestBody Long researchDetailid){
        ResearchDetail researchDetail = researchDetailService.selectDetailById(researchDetailid);
        return researchDetailService.getPollDetails(researchDetail);
    }
    @ResponseBody
    @RequestMapping(value = "/getResearch", produces = "application/json")
    public PageBean<Research> getResearch(@RequestBody String string){
        return researchService.findResearchsByPage(1,7,2,string);
    }
    @ResponseBody
    @RequestMapping(value = "/researchlist", produces = "application/json")
    public PageBean<Research> getList(int pageNow,int pageSize){
        System.out.println(researchService.findResearchsByPage(pageNow,pageSize,2,null));
        return researchService.findResearchsByPage(pageNow,pageSize,2,null);
    }
}